package ${packageName}.viewModel;

import android.app.Application;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableBoolean;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import ${packageName}.item.RecycleViewItemViewModel;
import ${applicationPackage}.BR;
import ${applicationPackage}.R;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;


public class ${viewModelName} extends BaseViewModel {
    
    public MutableLiveData<${itemViewModelName}> clickItemLiveData = new MutableLiveData();
    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        //下拉刷新完成
        public ObservableBoolean finishRefreshing = new ObservableBoolean(false);
        //上拉加载完成
        public ObservableBoolean finishLoadMore = new ObservableBoolean(false);
    }

    public ${viewModelName} (@NonNull Application application) {
        super(application);
    }

    //给RecyclerView添加ObservableList
    public ObservableList<${itemViewModelName}> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding
    public ItemBinding<${itemViewModelName}> itemBinding = ItemBinding.of(BR.viewModel, R.layout.${itemLayoutName});
    //给RecyclerView添加Adpter，请使用自定义的Adapter继承BindingRecyclerViewAdapter，重写onBindBinding方法，里面有你要的Item对应的binding对象
    public final BindingRecyclerViewAdapter<${itemViewModelName}> adapter = new BindingRecyclerViewAdapter<>();
    //下拉刷新
    public BindingCommand onRefreshCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
 //           ToastUtils.showShort("下拉刷新");
 //           requestNetWork();
        }
    });
	
    //上拉加载
    public BindingCommand onLoadMoreCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

        }
    });

    /**
     * 网络请求方法，在ViewModel中调用，Retrofit+RxJava充当Repository，即可视为Model层
     */
    public void requestNetWork() {
//        RetrofitClient.getInstance().create(DemoApiService.class)
//        uc.finishRefreshing.set(!uc.finishRefreshing.get());
    }

    /**
     * 获取条目下标
     *
     * @param itemViewModel
     * @return
     */
    public int getPosition(${itemViewModelName} itemViewModel) {
        return observableList.indexOf(itemViewModel);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
